package com.example.aqarapp.view.adapter;

import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.entity.node.BaseNode;
import com.chad.library.adapter.base.provider.BaseNodeProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.aqarapp.entity.BulbInfo;
import com.example.aqarapp.entity.CurtainInfo;
import com.example.aqarapp.entity.DeviceInfo;
import com.example.aqarapp.entity.SocketInfo;
import com.example.aqarapp.entity.TwoBean;

import org.jetbrains.annotations.NotNull;

import aqarapp.R;

public class SecondProvider extends BaseNodeProvider {
    @Override
    public int getItemViewType() {
        return 2;
    }

    @Override
    public int getLayoutId() {
        return R.layout.test2;
    }

    @Override
    public void convert(@NonNull BaseViewHolder baseViewHolder, BaseNode baseNode) {
        DeviceInfo deviceInfo = (DeviceInfo)baseNode;
        int gatewayClosedColor = getContext().getResources().getColor(R.color.gray_D8D8D8);
        //判断当前设备网关是否离线，离线则置灰且不可点击
        baseViewHolder.getView(R.id.test_device_list_info_view).setClickable(false);
        if(deviceInfo.getState().equals("0")){
            baseViewHolder.setBackgroundColor(R.id.test_device_list_view,gatewayClosedColor);
        }
        Log.d("liyao888","deviceInfo name ="+deviceInfo.getDeviceName());
        if (deviceInfo.getBaseDeviceInfo() instanceof BulbInfo) {
            baseViewHolder.setBackgroundResource(R.id.test_device_list_info_iv, R.mipmap.lightbulb_icon);
        } else if (deviceInfo.getBaseDeviceInfo() instanceof SocketInfo) {
            baseViewHolder.setBackgroundResource(R.id.test_device_list_info_iv, R.mipmap.socket);
        } else if (deviceInfo.getBaseDeviceInfo() instanceof CurtainInfo) {
            baseViewHolder.setBackgroundResource(R.id.test_device_list_info_iv, R.mipmap.curtain);
        }
        baseViewHolder.setText(R.id.test_device_list_info_tv,deviceInfo.getDeviceName());
    }


}
